import { Route } from 'react-router-dom';
import { getToken } from 'utils/storage';

export default function AuthRoute(props) {
  // 对象的剩余运算
  const { component: Comp, ...rest } = props;
  // console.log(rest);
  // console.log(props);
  return (
    <Route
      {...rest}
      render={(props) => {
        // 判断有无token
        if (getToken()) {
          return <Comp {...props} />;
        } else {
          // 没有token返回登录页
          props.history.push('/login');
        }
      }}
    ></Route>
  );
}
